<template>
<div>
  <el-breadcrumb separator="/" style="padding-left:10px;padding-bottom:10px;font-size:12px;">
    <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
    <el-breadcrumb-item>物资管理</el-breadcrumb-item>
    <el-breadcrumb-item>物资出库</el-breadcrumb-item>
  </el-breadcrumb>
  <el-button type="primary">查询</el-button>
  <el-button type="success" @click="delDialogVisible=true">发放</el-button>
  <el-dialog title="物资发放" :visible.sync="delDialogVisible" width="30%" >
    <el-form :model="delForm"  ref="ruleFormDel" label-width="100px" class="demo-ruleForm">
      <el-form-item label="物资名称">
        <el-select v-model="delForm.pName" placeholder="请选择物资名称">
          <el-option label="N95口罩" value="N95口罩"></el-option>
          <el-option label="普通医用口罩" value="普通医用口罩"></el-option>
          <el-option label="普通温度计" value="普通温度计"></el-option>
          <el-option label="生理盐水" value="生理盐水"></el-option>
          <el-option label="东北大米" value="东北大米"></el-option>
          <el-option label="防毒面具" value="防毒面具"></el-option>
          <el-option label="霸王洗发水" value="霸王洗发水"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="具体地址" prop="name">
        <el-input v-model="delForm.name"></el-input>
      </el-form-item>
      <el-form-item label="数量" prop="productNumber">
        <el-input v-model="delForm.productNumber"></el-input>
      </el-form-item>
      <el-form-item label="联系人" prop="contact">
        <el-input v-model="delForm.contact"></el-input>
      </el-form-item>
      <el-form-item label="电话" prop="phone">
        <el-input v-model="delForm.phone"></el-input>
      </el-form-item>
<!--      <el-form-item label="数量" prop="name">-->
<!--        <el-input v-model="ruleForm.name"></el-input>-->
<!--      </el-form-item>-->
      <el-form-item label="发放地址" prop="address">
        <el-input v-model="delForm.address"></el-input>
      </el-form-item>
<!--      <el-form-item label="活动区域" prop="region">-->
<!--        <el-select v-model="ruleForm.region" placeholder="请选择活动区域">-->
<!--          <el-option label="区域一" value="shanghai"></el-option>-->
<!--          <el-option label="区域二" value="beijing"></el-option>-->
<!--        </el-select>-->
<!--      </el-form-item>-->
    </el-form>
    <span slot="footer" class="dialog-footer">
    <el-button @click="delDialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="delProductStock ">确 定</el-button>
  </span>
  </el-dialog>
  <el-table :data="ProductList" stripe style="width: 100%">
    <el-table-column prop="outNum" label="发放单号" ></el-table-column>
    <el-table-column prop="type" label="发放类型"></el-table-column>
    <el-table-column prop="priority" label="紧急程度" ></el-table-column>
    <el-table-column prop="name" label="发放地点" ></el-table-column>
    <el-table-column prop="productNumber" label="总数" ></el-table-column>
    <el-table-column prop="phone" label="联系方式" ></el-table-column>
    <el-table-column prop="status" label="状态" ></el-table-column>
  </el-table>
</div>
</template>

<script>
export default {
  name: 'OutStocks1',
  data () {
    return {
      ProductList: [],
      delForm: {
        pName: '',
        name: '',
        productNumber: '',
        contact: '',
        phone: '',
        address: ''
      },
      productStock: 0,
      delDialogVisible: false
    }
  },
  mounted () {
    this.getAllOutProduct()
  },
  methods: {
    // 显示出库物资信息
    async getAllOutProduct () {
      const { data: res } = await this.$http.get('biz/pro/getAllOutProduct')
      if (res.code !== 200) {
        return this.$message.error(res.msg)
      }
      console.log(res.data)
      this.ProductList = res.data
      this.ProductList.forEach(function (item) {
        if (item.status === 0) {
          item.status = '已出库'
        }
        if (item.type === 0) {
          item.type = '直接出库'
        }
        if (item.type === 1) {
          item.type = '审核出库'
        }
      })
    },
    // 物资出库
    async delProductStock () {
      console.log(this.delForm.pName)
      this.$refs.ruleFormDel.validate(async (valid) => {
        if (valid === true) {
          const { data: res } = await this.$http.post('biz/pro/delProductStock', this.delForm)
          if (res.code !== 200) {
            this.$message.error(res.msg)
            alert(res.msg)
            return false
          }
          this.$message.success(res.msg)
          await this.getAllOutProduct()
          this.delDialogVisible = false
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
